package com.acme.bankapp.domain.bank;

import java.io.Serializable;

import com.acme.bankapp.domain.exceptions.NotEnoughFundsException;

public class SavingAccount extends AbstractAccount implements Serializable {
	
	public SavingAccount(final double amount, final int id) {
		super(amount, id);		
	}
	
	public SavingAccount(final int id) {
		super(0, id);		
	}
	
	public SavingAccount() { 
		this(0, 0);
	}
			
	@Override
	public String toString() {
		return "SavingAccount #" + id + ", the balance is " + balance;
	}

	public double maximumAmountToWithdraw() {
		return balance;
	}
	
	public void withdraw(final double amount) throws NotEnoughFundsException {
		if(amount <= 0) {
			throw new IllegalArgumentException("the wrong amount");
		}
		if (this.balance < amount) {
			double exceed = (amount - balance);
			throw new NotEnoughFundsException ("request exceeds the balance on " + exceed, exceed);
		}
		this.balance -= amount;		
	}

}
